﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Playables;

namespace Nirvana
{
	/// <summary>
	/// 用于等待CG结束并播放下一段CG.
	/// </summary>
	public sealed class CGNext : MonoBehaviour
	{
		[SerializeField]
		private PlayableDirector current,next;
		private double duration;

		void Awake()
        {
			if (current != null) this.duration = this.current.duration;
        }

		void Update()
        {
			if (this.current == null || this.next == null) return;

			if(this.current.state == PlayState.Playing)
            {
				var delta = this.current.time - this.duration;
                if (Math.Abs(delta)<0.0001f)
				{
					this.current.Stop();
					this.next.Play();
					Debug.Log("Play: " + this.next.name);
                }
            }
        }


	}
}

